﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Vortex.Drawing {

	/// <summary>
	/// Enumeration of canvas state flags
	/// </summary>
	[Flags]
	enum CanvasStateChanges {
		None = 0,
		VertexShader = 1 << 0,
		PixelShader = 1 << 1,
		Blending = 1 << 2,
		AlphaTest = 1 << 3,
		ZEffect = 1 << 4,
		Clipping = 1 << 5,

		TextureBase = 1 << 16,
		PrimaryTexture = TextureBase << 0,
		BrushTexture = TextureBase << 1,
		Texture2 = TextureBase << 2,
		Texture3 = TextureBase << 3,
		Texture4 = TextureBase << 4,
		Texture5 = TextureBase << 5,
		Texture6 = TextureBase << 6,
		Texture7 = TextureBase << 7,

		CustomTextures = Texture2 | Texture3 | Texture4 | Texture5 | Texture6 | Texture7,
		AnyTexture = PrimaryTexture | BrushTexture | CustomTextures,

		ForceVertexShader = 1 << 31,
		AnyVertexShader = ForceVertexShader | VertexShader,
		All = -1
	}

	/// <summary>
	/// Contains whole set of canvas states
	/// </summary>
	public class CanvasStates {
		public const int MAX_TEXTURE_COUNT = 8;
		public const int PRIMARY_TEXTURE_INDEX = 0;
		public const int BRUSH_TEXTURE_INDEX = 1;
		public const int OTHER_TEXTURES_BASE_INDEX = 2;

		private BaseTexture[] _textures = new BaseTexture[MAX_TEXTURE_COUNT];

		///<summary>Primary texture for drawing all of stuff</summary>
		public BaseTexture PrimaryTexture {
			get { return _textures[PRIMARY_TEXTURE_INDEX]; }
			set { _textures[PRIMARY_TEXTURE_INDEX] = value; }
		}

		///<summary>Additional brush texture for drawing overlays of stuff</summary>
		public BaseTexture BrushTexture {
			get { return _textures[BRUSH_TEXTURE_INDEX]; }
			set { _textures[BRUSH_TEXTURE_INDEX] = value; }
		}
		
		///<summary>Current vertex shader used to process drawing vertices</summary>
		public VertexShader VertexShader;
		
		///<summary>Current pixel shader for calculation end-pixel color</summary>
		public PixelShader PixelShader;
		
		///<summary>Blending states</summary>
		public Blending Blending;

		///<summary>Alpha test</summary>
		public AlphaTest AlphaTest;

		/// <summary>Z-Effect state </summary>
		public ZEffect ZEffect;

		///<summary>Rectangular clipping</summary>
		public Clipping Clipping;

		/// <summary>
		/// Gets the array of used textures.
		/// </summary>
		/// <value>The textures array.</value>
		public BaseTexture[] Textures {
			get { return _textures; }
		}

	}
}
